﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Model;
using BLL;
using Microsoft.AspNetCore.Authorization;

namespace OAElectronics.Controllers
{
    [Authorize(Policy = "开发部")]
    public class TechnologicalController : Controller//流程管理
    {
        private readonly TechnologicalBLL technologicalBLL;
        
        public TechnologicalController(TechnologicalBLL bLL)
        {
            this.technologicalBLL = bLL;
        }
        public IActionResult Index()
        {
            return View();
        }
        //申请状态
        public IEnumerable<Astate> SelAstates()
        {
            return technologicalBLL.SelAstate();
        }
        //请假类型查询
       
        public IEnumerable<Leave_type> SelLeave_type()
        {
            return technologicalBLL.Leave_Types();
        }
        //请假申请待办查询
        
        public IEnumerable<Leave> SelLeaves([FromBody]Leave l)
        {
            if (l.SName!="")
            {
                return technologicalBLL.SelLeave().Where(a => a.SName.Contains(l.SName));
            }
            else
            {
                return technologicalBLL.SelLeave();
            }
        }
        //请假申请添加
        public int AddLeave([FromBody]Leave l)
        {
            if (technologicalBLL.AddLeave(l)!=0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        //申请待办页面
        
        public IActionResult Dealt()
        {
            return View();
        }
        //加班申请添加
       
        public int AddWork([FromBody]work w)
        {
            if (technologicalBLL.AddWork(w)!=0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        //请假申请待办查询
       
        public IEnumerable<work> SelWorks([FromBody]work w)
        {
            IEnumerable<work> list = null;

            if (w.WName != null)
            {
                list = technologicalBLL.SelWorks().Where(a => a.WName.Contains(w.WName));
            }
            else
            {
                list = technologicalBLL.SelWorks();
            }
            return list;
        }
        //请假审核
        [Authorize(Roles = "部门经理,总经理,总监")]
        public int examine([FromBody]Leave l)
        {
            if (technologicalBLL.examine(l) != 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        //出差申请添加
        public int AddTravel([FromBody]Travel t)
        {
            if (technologicalBLL.AddTravel(t)!=0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        //出差申请待办查询
       
        public IEnumerable<Travel> SelTravels([FromBody]Travel t)
        {
            if (t.travel_name!=null)
            {
                return technologicalBLL.Travels().Where(a => a.travel_name.Contains(t.travel_name));
            }
            else
            {
                return technologicalBLL.Travels();
            }
        }
        //添加活动申请
        [Authorize(Roles = "部门经理")]
        public int AddActivity([FromBody]Activity a)
        {
            if (technologicalBLL.AddActivity(a)!=0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        //活动待办查询
        
        public IEnumerable<Activity> SelectActivities([FromBody] Activity a)
        {
            if (a.Activity_NAME!=null)
            {
                return technologicalBLL.Activities().Where(a => a.Activity_NAME.Contains(a.Activity_NAME));
            }
            else
            {
                return technologicalBLL.Activities();
            }
        }
        //加班审核
        [Authorize(Roles = "总经理,部门经理")]
        public int examineWork([FromBody]work w)
        {
            if (technologicalBLL.examineWork(w) != 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        //出差审核
        [Authorize(Roles = "总经理")]
        public int examineTravels([FromBody]Travel t)
        {
            if (technologicalBLL.examineTravels(t)!=0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
    }
}
